/**
 * 
 */
package com.logistics.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.logistics.ExpressCompany;
import com.logistics.ExpressProperty;
import com.logistics.ExpressPropertyQueryParam;
import com.logistics.admin.AdminGenericBaseAction;
import com.logistics.service.ExpressCompanyService;
import com.logistics.service.ExpressPropertyService;

/**
 * @author hzz
 *
 * 2014年5月12日
 */

@Component("expressPropertyAdminAction")
@Scope("prototype")
public class ExpressPropertyAdminAction extends AdminGenericBaseAction<ExpressProperty, ExpressPropertyService> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7409870258987278265L;

	private ExpressPropertyService service;
	
	@Autowired
	public void setService(ExpressPropertyService service) {
		this.service = service;
	}

	private ExpressCompanyService companyService;
	
	@Autowired
	public void setCompanyService(ExpressCompanyService companyService) {
		this.companyService = companyService;
	}

	@Override
	public ExpressPropertyService getService() {
		return service;
	}
	
	private ExpressProperty property;

	public ExpressProperty getProperty() {
		return property;
	}

	public void setProperty(ExpressProperty property) {
		this.property = property;
	}

	private List<ExpressProperty> properties;
	
	public List<ExpressProperty> getProperties() {
		return properties;
	}

	public void setProperties(List<ExpressProperty> properties) {
		this.properties = properties;
	}
	
	private int companyId;
	
	public int getCompanyId() {
		return companyId;
	}

	public void setCompanyId(int companyId) {
		this.companyId = companyId;
	}
	
	private List<ExpressCompany> companies; 

	public List<ExpressCompany> getCompanies() {
		return companies;
	}

	public void setCompanies(List<ExpressCompany> companies) {
		this.companies = companies;
	}

	private ExpressPropertyQueryParam param;
	
	public ExpressPropertyQueryParam getParam() {
		return param;
	}

	public void setParam(ExpressPropertyQueryParam param) {
		this.param = param;
	}

	public String list() {
		if (param == null) {
			param = new ExpressPropertyQueryParam();
		}
		
		param.setPaging(getPaging());

		properties = service.query(param);
		
		return LIST;
		
	}

	@Override
	protected ExpressProperty initEntityForAdd() {
		if (companyId > 0) {
			property.setCompany(new ExpressCompany(companyId));
		}
		return property;
	}

	@Override
	protected void initEditForm() {
		companies = companyService.query(null);
		property = service.getById(getId());
		if (property.getCompany() != null) {
			companyId = Integer.valueOf(property.getCompany().getEntityId());
		} else {
			companyId = 0;
		}
	}
	
	@Override
	protected void initAddForm() {
		companies = companyService.query(null);
		companyId = 0;
	}
	
}
